@import (reference) '../style/variables.less';

.@{prefix}-search {
  display: inline-block;
  flex-basis: 180px;

  &-input {
    width: 100%;
    height: 36px;
    padding: 0 14px 0 38px;
    color: @c-heading;
    font-size: 14px;
    border: 0;
    outline: none;
    transition: all 0.2s;
    border-radius: 18px;
    background: url('')
      #f5f6f7 no-repeat left 14px center / 16px;
    appearance: none;

    [data-prefers-color=dark] & {
      color: @c-secondary-dark;
      background: url('')
      #ffffff1f no-repeat right 14px center / 16px;
    }

    &:focus {
      box-shadow: 0 0 0 1px fade(@c-primary, 20%) inset;
    }

    &:not(:focus) + ul:not(:hover) {
      visibility: hidden;
    }

    &::-webkit-input-placeholder {
      color: #999;
      font-size: 12px;
    }
  }

  > ul {
    list-style: none;
    position: absolute;
    top: 100%;
    left: 0;
    z-index: 10;
    margin: 8px 0 0;
    min-width: 280px;
    max-width: 400px;
    max-height: 230px;
    padding: 6px 0;
    background-color: #fff;
    border: 1px solid @c-border;
    border-radius: 1px;
    box-shadow: 0 2px 20px 0 rgba(0, 0, 0, 0.05);
    box-sizing: border-box;
    overflow-y: auto;

    [data-prefers-color=dark] & {
      border: none;
      background-color: @c-bg-dark;
      box-shadow: 0 3px 6px -4px rgba(0, 0, 0, 0.48), 0 6px 16px 0 rgba(0, 0, 0, 0.32), 0 9px 28px 8px rgba(0, 0, 0, 0.2);
    }

    &:empty {
      display: none;
    }

    li {
      font-size: 15px;

      a {
        display: block;
        padding: 6px 20px;
        color: @c-secondary;
        text-decoration: none;
        line-height: 1.5715;
        transition: background-color 0.3s;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;

        [data-prefers-color=dark] & {
          color: @c-secondary-dark;
        }

        &:hover {
          color: @c-primary;
          background-color: @c-light-bg;

          [data-prefers-color=dark] & {
            color: @c-primary-dark;
            background-color: @c-light-bg-dark;
          }
        }
      }

      span:first-child:not(.@{prefix}-search-highlight) {
        position: relative;
        display: inline-block;
        max-width: 50%;
        padding-right: 26px;
        vertical-align: bottom;
        overflow: hidden;
        text-overflow: ellipsis;
        opacity: 0.8;

        &::after {
          content: '>';
          position: absolute;
          top: 50%;
          right: 6px;
          opacity: 0.6;
          transform: translateY(-54%);
        }
      }
    }
  }

  &-empty {
    margin: 6px 0;
    opacity: 0.6;
    fill: @c-text;
    [data-prefers-color=dark] & {
      fill: @c-text-dark;
    }
  }

  &-highlight {
    padding: 2px 0;
    color: #736b2d;
    vertical-align: bottom;
    background: #fff9cb;

    [data-prefers-color=dark] & {
      color: @c-text;
    }
  }

  @media only screen and (max-width: 1024px) {
    margin-right: -14px;

    > input:not(:focus) {
      color: transparent;
      width: 36px;
      padding-right: 0;
      box-shadow: none;
      cursor: pointer;
      background-position: left 12px center;

      + ul {
        transition: 0.1s visibility;
        visibility: hidden;
      }
    }
  }

  @media @mobile {
    position: absolute;
    top: 9px;
    right: 24px;
    display: block !important;

    > ul {
      right: 0;
      left: auto;
    }
  }
}
